/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rsbot.injector;

import org.rsbot.injector.data.ClassData;
import org.rsbot.injector.data.GetterData;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Logger;
import org.rsbot.client.Model;
import org.rsbot.injector.data.FieldData;
import org.rsbot.injector.data.MasterSetterData;
import org.rsbot.injector.data.ModelData;

import org.rsbot.loader.asm.Opcodes;
import org.rsbot.loader.asm.Type;
import org.rsbot.util.GlobalConfiguration;
import org.rsbot.util.Serializer;

/**
 * @author Nader Sleiman
 */
public class UpdaterTest implements Opcodes {

    static Logger log = Logger.getLogger(UpdaterTest.class.getName());

    public static void main(String[] argV) throws IOException {
        System.out.println(GlobalConfiguration.Paths.getHomeDirectory());
        Vector v = new Vector();

        ClassDataVector<ClassData> vec = new ClassDataVector<ClassData>();
        ClassData inter = new ClassData("vfa");

        //d.interfaces.add("org/rsbot/client/Client");
        GetterData mxg = new GetterData();
        mxg.access = ACC_PUBLIC + ACC_FINAL;
        mxg.isStatic = false;
        mxg.name = "getMasterXTest";
        mxg.desc = "()I";
        mxg.field_name = "master_x_test";
        mxg.field_owner = "vfa";
        mxg.field_desc = "I";
        mxg.signature = null;
        mxg.exceptions = null;

        GetterData myg = new GetterData();
        myg.access = ACC_PUBLIC + ACC_FINAL;
        myg.isStatic = false;
        myg.name = "getMasterYTest";
        myg.desc = "()I";
        myg.field_name = "master_y_test";
        myg.field_owner = "vfa";
        myg.field_desc = "I";
        myg.signature = null;
        myg.exceptions = null;
        //add to getters
        inter.getters.add(mxg);
        inter.getters.add(myg);

        FieldData mx = new FieldData();
        mx.access = ACC_PUBLIC;
        mx.desc = "I";
        mx.name = "master_x_test";

        FieldData my = new FieldData();
        my.access = ACC_PUBLIC;
        my.desc = "I";
        my.name = "master_y_test";
        //add to fields
        inter.fields.add(mx);
        inter.fields.add(my);

        //add model test field
        ClassData mt = new ClassData("kd");
        FieldData fd = new FieldData();
        fd.access = ACC_PUBLIC;
        fd.desc = Type.getDescriptor(Model.class);
        fd.name = "model_test";

        mt.fields.add(fd);
        //add model getter
        GetterData gd = new GetterData();
        gd.access = ACC_PUBLIC + ACC_FINAL;
        gd.desc = "()" + Type.getDescriptor(Model.class);
        gd.name = "getModelTest";
        gd.field_desc = Type.getDescriptor(Model.class);
        gd.field_owner = "kd";
        gd.field_name = "model_Test";
        gd.isStatic = false;
        mt.getters.add(gd);


        //add classdatas to vec
        vec.add(inter);
        vec.add(mt);

        //masterX/Y
        MasterSetterData md = new MasterSetterData();
        md.owner = "nm";
        md.aload = 12;
        md.interface_name = "vfa";
        md.master_x_iload = 1;
        md.master_y_iload = 3;
        md.method_name = "a";
        md.method_desc = "(IIIIZ[Lvfa;IIIII)V";
        md.master_x_name = "master_x_test";
        md.master_y_name = "master_y_test";


//ModelHack Test(append instructions to methods used as setters.
        ModelDataVector<ModelData> mdv = new ModelDataVector<ModelData>();
        ModelData modd = new ModelData();
        modd.class_name = "kd";//interactiveobject 1
        modd.model_field_name = "model_test";
        modd.method_name = "b";
        modd.method_desc = "(ILha;)Lww;";
        //add modeldata to mdv
        mdv.add(modd);

        //add all to main Vector(Sequentially)
        v.add(vec);
        v.add(mdv);
        v.add(md);


        new File(GlobalConfiguration.Paths.Resources.DATA).createNewFile();
        if (!Serializer.serlialize(v, new File(GlobalConfiguration.Paths.Resources.DATA))) {
            log.info("failed to retrive hooks file");
        }
    }
}
